using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using Common.Enum;

namespace Converters
{
	public class EnumVisibilityConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value != null && value != DependencyProperty.UnsetValue && parameter != null && Enum.IsDefined(value.GetType(), parameter))
			{
				object obj = Enum.Parse(value.GetType(), parameter.ToString());
				if (obj is EProjectType && (EProjectType)obj == EProjectType.Melt && (EProjectType)value == EProjectType.HRM)
				{
					return Visibility.Visible;
				}
				return (!obj.Equals(value)) ? Visibility.Collapsed : Visibility.Visible;
			}
			return Visibility.Collapsed;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return value;
		}
	}
}
